package com.github.hongkaiwen.rxjava.play.problem1;

import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;

public class FromCallableSolve extends Base {

    public static void main(String... args) throws InterruptedException {
        FromCallableSolve fromCallableSolve = new FromCallableSolve();

        Observable<Integer> c1 = Observable.fromCallable(() -> fromCallableSolve.a()).subscribeOn(Schedulers.io());
        Observable<Integer> c2 = Observable.fromCallable(() -> fromCallableSolve.b()).subscribeOn(Schedulers.io());
        Observable<Integer> c3 = Observable.fromCallable(() -> fromCallableSolve.c()).subscribeOn(Schedulers.io());

        Observable.merge(c1, c2, c3).reduce((i, j) -> i + j).subscribe(fromCallableSolve::result);

        System.out.println("finished.");
        TimeUnit.SECONDS.sleep(6);
    }



}
